#include <iostream>
#include "House.h"
#include "UsefulFunc.h"

House::House(const std::string name, const std::vector<Player *> players, Deck *deck) : GenericPlayer(name),houseName(name),
																						deck(deck), players(players)
{
	//houseName = name;
	//this->deck = deck;
	//this->players = players;
}

House::~House()
{
	for(int i=0;i<players.size();++i)
	{
		delete players[i];
	}
	players.clear();
	delete deck;
}

void House::askIfWantsOneCard(Player *onePlayer) {
	/*std::cout << onePlayer->getName() <<", do you want one more card? <y/n>";
	char again = 'y';
	std::cin >> again;*/
	char again = cinTakeCharYorN(onePlayer->getName() +", do you want one more card? <y/n>");
	
	if(again != 'y' && again != 'Y') //If player answers yes, he wants to hit
		onePlayer->setNotHitting();
}

void House::dealOneCardToItself() {
	deck->dealOneCard(*this);
}

bool House::isHitting() const {
	if(this->getTotal() < 17)
		return true;
	else 
		return false;
}


void House::DealFirstRound(){
	DealTwoCardsToItself();
	for(int i=0; i<players.size(); ++i){
		DealTwoCardsToOnePlayer(players[i]);
	}
}

void House::dealOneCardToOnePlayer(Player *onePlayer){
	deck->dealOneCard(*onePlayer);
}

std::string House::GetName() const {
	return houseName;
}

void House::DealTwoCardsToOnePlayer(Player *onePlayer)
{
	deck->dealOneCard(*onePlayer);
	deck->dealOneCard(*onePlayer);
}

void House::DealTwoCardsToItself()
{
	deck->dealOneCard(*this);
	deck->dealOneCard(*this);
	(this->getCard(1))->setVisibility(false);
}

void House::showLastCard()
{
	(this->getCard(1))->setVisibility(true);
}